package problem36;
//36.有效的数独
//https://leetcode.cn/problems/valid-sudoku

class Solution {
    boolean[][] row = new boolean[10][10];
    boolean[][] col = new boolean[10][10];
    boolean[][][] grid = new boolean[3][3][10];
    public boolean isValidSudoku(char[][] board) {
        for(int i = 0; i<board.length; i++) {
            for(int j = 0; j<board[i].length; j++) {
                if(board[i][j] != '.') {
                    int x = board[i][j] - '0';
                    if(row[i][x]) return false;
                    row[i][x] = true;
                    if(col[j][x]) return false;
                    col[j][x] = true;
                    if(grid[i/3][j/3][x]) return false;
                    grid[i/3][j/3][x] = true;
                }
            }
        }
        return true;
    }
}